import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { WechatBotService } from 'src/app/service/wechat-bot.service';

@Component({
  selector: 'app-wechat-bot',
  templateUrl: './wechat-bot.component.html',
  styleUrls: ['./wechat-bot.component.less']
})
export class WechatBotComponent implements OnInit {
  alive: boolean;
  imageUrl: string;
  constructor(
    private message: NzMessageService,
    private wechatBotService: WechatBotService
  ) { }
  login() {
    this.wechatBotService.login()
      .subscribe((data: any) => {
        this.imageUrl = data.url;
      });
  }
  logout() {
    this.wechatBotService.logout().subscribe();
  }
  localgetcontact() {
    this.message.warning('功能暂未实现');
  }
  webwxgetcontact() {
    this.message.warning('功能暂未实现');
  }
  ngOnInit() {
    const checkAlive = () => {
      this.wechatBotService.checkAlive()
        .subscribe(data => {
          this.alive = data
          setTimeout(checkAlive, 1000 * 10)
        });
    };
    checkAlive();
  }

}
